﻿using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace TeacherLeftHand.Model
{
    /// <summary>
    /// Represent Teaching Contains aka Phương pháp giảng dạy
    /// </summary>
    public class TeachingMethod : IDataErrorInfo, IData
    {
        #region Const

        public const string Individual = "Cá nhân";
        public const string Teamwork = "Nhóm";
        public const string All = "Cả lớp";

        #endregion 

        #region properties
        private int _id;
        private string _name;
        //private int _teamSize;
        //private string _tools;
        private List<string> _preferredSubject;
        private int _preferredClassLevel;
        private string _content;
        private string _note;

        /// <summary>
        /// Get Teaching method ID
        /// </summary>
        public int ID
        {
            get { return _id; }
            set { _id = value; }
        }

        /// <summary>
        /// Get or set Teaching Contains name
        /// </summary>
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        ///// <summary>
        ///// get or set teaching method team size
        ///// </summary>
        //public int TeamSize
        //{
        //    get { return _teamSize; }
        //    set { _teamSize = value; }
        //}

        ///// <summary>
        ///// get or set teaching method required tools
        ///// </summary>
        //public string Tools
        //{
        //    get { return _tools; }
        //    set { _tools = value; }
        //}

        /// <summary>
        /// get or set teaching method preferred subject
        /// </summary>
        public List<string> PreferredSubject
        {
            get { return _preferredSubject; }
            set { _preferredSubject = value; }
        }

        /// <summary>
        /// get or set teaching method preferred class level
        /// </summary>
        public int PreferredClassLevel
        {
            get { return _preferredClassLevel; }
            set { _preferredClassLevel = value; }
        }

        /// <summary>
        /// Get or set teaching method content
        /// </summary>
        public string Content
        {
            get { return _content; }
            set { _content = value; }
        }

        /// <summary>
        /// Get or set Teaching method note
        /// </summary>
        public string Note
        {
            get { return _note; }
            set { _note = value; }
        }

        #endregion

        #region constructor
        public TeachingMethod(int id = -1,string name = "",List<string> preferredSubject = null,
            int preferredClassLevel = 1, string content = "", string note = "")
        {
            _id = id;
            Name = name;
            PreferredSubject = preferredSubject;
            PreferredClassLevel = preferredClassLevel;
            Content = content;
            Note = note;
        }

        public TeachingMethod(TeachingMethod source)
        {
            ID = source.ID;
            Name = source.Name;
            PreferredSubject = source.PreferredSubject;
            PreferredClassLevel = source.PreferredClassLevel;
            Content = source.Content;
            Note = source.Note;
        }

        public TeachingMethod()
        {
            ID = -1;
            Name = "";
            PreferredSubject = new List<string>();
            PreferredClassLevel = 0;
            Content = "";
            Note = "";
        }
        #endregion

        #region methods

        //private static string AutoGenerateID()
        //{
        //    return "TM" + new Random() + "" + new DateTime();
        //}

        #endregion

        #region Implementation of IDataErrorInfo

        /// <summary>
        /// Gets the error message for the property with the given name.
        /// </summary>
        /// <returns>
        /// The error message for the property. The default is an empty string ("").
        /// </returns>
        /// <param name="columnName">The name of the property whose error message to get. </param>
        public string this[string columnName]
        {
            get { string msg = null;
                switch (columnName)
                {
                    // name is required field
                    case "Name" :
                        if (string.IsNullOrEmpty(Name))
                        {
                            msg = "Required field";
                        }
                        break;

                    // content is required field
                    case "Content":
                        if (string.IsNullOrEmpty(Content))
                        {
                            msg = "Required field";
                        }
                        break;

                    //// team size is required field
                    //case "TeamSize":
                    //    if (TeamSize < 1)
                    //    {
                    //        msg = "Required field";
                    //    }
                    //    break;
                    
                    //other fields are optional
                    case "PreferredClassLevel":
                    case "PreferredSubject":
                    //case "Tools":
                    case "Note":
                    case "ID":
                        break;
                    default:
                        throw new ArgumentException(
                        "Unrecognized property: " + columnName);
                }
                return msg;
            }
        }

        /// <summary>
        /// Gets an error message indicating what is wrong with this object.
        /// </summary>
        /// <returns>
        /// An error message indicating what is wrong with this object. The default is an empty string ("").
        /// </returns>
        public string Error
        {
            get { return null; }
        }

        #endregion
    }
}
